package com.distribution.system.openapi.domain;

import com.distribution.common.constant.HttpStatus;
import com.distribution.common.utils.DateUtils;
import com.distribution.common.utils.StringUtils;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author: GodLu
 * @create: 2024-04-15 17:33
 * @description: TODO
 */
@Getter
public class ApiResult implements Serializable {
    @Setter
    private int code;
    @Setter
    private String msg;
    @Setter
    private String time;
    private Object data = null;

    public ApiResult(int code, String msg){
        this.code = code;
        this.msg = msg;
        this.time = DateUtils.dateTimeApi();
    }

    public ApiResult(int code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.time = DateUtils.dateTimeApi();
        if (StringUtils.isNotNull(data))
        {
            this.data = data;
        }
    }

    /**
    * @Author: GodLu
    * @Date: 2024/4/16 22:01
    * @Description: 返回成功消息及数据
    * @param message 返回信息
    * @param data 返回数据
    * @return: ApiResult
    */
    public static ApiResult success(String message,Object data)
    {
        return new ApiResult(HttpStatus.SUCCESS, message, data);
    }

    public static ApiResult success(String message)
    {
        return new ApiResult(HttpStatus.SUCCESS, message, null);
    }

    public static ApiResult success(Object data)
    {
        return new ApiResult(HttpStatus.SUCCESS,"请求成功", data);
    }

    /**
    * @Author: GodLu
    * @Date: 2024/4/17 16:44
    * @Description: 返回失败信息
    * @param code 错误码
    * @param message 错误提示
    * @return: ApiResult
    */
    public static ApiResult error(int code,String message){
        return new ApiResult(code,message);
    }
    public static ApiResult error(String message){
        return new ApiResult(500,message);
    }
}
